﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Presenters;
using University.Workshop.Model;
using University.Workshop.Presenters.MedicalSuppliesFolder;

namespace University.Workshop.WinApp
{
    public partial class GetAllMedicalSupplies : Form , ISearchMedicalSupplies
    {
        PresenterSearchMedicalSupplies presenter;
    //    MedicalSupplies selectedItem;
        int index;
        MedicalSupplies item = new MedicalSupplies();
        List<MedicalSupplies> supplies;

        public GetAllMedicalSupplies()
        {
            InitializeComponent();
            presenter = new PresenterSearchMedicalSupplies(this);
        }

        private void GetAllMedicalSupplies_Load(object sender, EventArgs e)
        {
            index = -1;
            supplies = (List<MedicalSupplies>) presenter.LoadMedicalSupplies();
            dataGridView1.DataSource = supplies;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            {
                try
                {
                    if (index != -1)
                    {

                        label2.Text = dataGridView1.CurrentRow.Cells["QuantityAvaliable"].Value.ToString();
                        int j = int.Parse(label2.Text);
                        UpdateMedicalSupplies upmedicasupplies = new UpdateMedicalSupplies(item);
                        this.Visible = false;
                        if (upmedicasupplies.ShowDialog() == DialogResult.Cancel)
                            this.Visible = true;
                        index = -1;
                        textBox1.Clear();
                        dataGridView1.DataSource = null;
                    }
                    else
                    {
                        MessageBox.Show("Seleccione un suministro medico");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }




        }

        public string ItemName
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            supplies = (List<MedicalSupplies>) presenter.LoadMedicalSupplies();
            dataGridView1.DataSource = supplies;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            index = e.RowIndex;
        }

       
    }
}
